<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link rel="stylesheet" type="text/css" th:href="@{/lib/layui/css/layui.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/css/view.css}"/>
    <title>提额</title>
</head>
<body class="layui-view-body">
    <div class="layui-content">
        <div class="layui-row">
            <div class="layui-card">
                <!--<div class="layui-card-header">用户修改密码</div>-->
                <form id="userForm" class="layui-form layui-card-body">
                  <div class="layui-form-item">
                    <input type="hidden" name="userid" th:value="${id}">
                    <label class="layui-form-label">现用户额度</label>
                    <div class="layui-input-block"><!--th:value="${user.tell}"-->
                      <input type="text"  th:value="${money}" th:readonly="true" autocomplete="off" class="layui-input">
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <label class="layui-form-label">新用户额度</label>
                    <div class="layui-input-inline">
                      <input type="text" name="usermoney" id="usermoney" required  lay-verify="usermoney" placeholder="不得低于现用户额度" autocomplete="off" class="layui-input">
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <div class="layui-input-block">
                      <input type="button" class="layui-btn layui-btn-blue" lay-submit lay-filter="save" th:value="保存"></input>
                      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                  </div>
                </form>  
            </div>
        </div>
    </div>
    <script type="text/javascript" th:src="@{/lib/layui/layui.all.js}"></script>
    <script type="text/javascript" th:src="@{/js/jquery-3.2.1.min.js}"></script>
    <script th:inline="javascript">
        /*<![CDATA[*/
        var contextPath = [[${#request.getContextPath()}]]; //获取当前应用路径
        var usermoney=[[${money}]];
        /*]]>*/
    </script>
    <script type="text/javascript">
        layui.use(['form'], function() {
            var form = layui.form
                , layer = layui.layer;

            //添加验证规则
            form.verify({
                usermoney : function (value,item) {
                    if(value < usermoney){
                        return "不得低于现用户额度";
                    }
                    if(value == usermoney){
                        return "不得与现用户额度相同";
                    }
                }
            });

            //监听提交
            form.on('submit(save)', function(data){
                var data = $("#userForm").serialize();
                $.ajax({
                    url: contextPath + "/home/addUserMoneySubmit",
                    type: "post",
                    data: data,
                    success: function (msg) {
                        layer.msg("保存成功",{
                            time:1000
                        },function () {
                            //关闭当前弹出层
                            var index=parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            parent.location.reload();
                        });
                    }
                });
            })
        });

    </script>
</body>
</html>